package homework;

public class Rectangle {
    private double length;
    private double width;

    public Rectangle() {
    }

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        if (length<=0){
            System.out.println("矩形的长和宽必须是正数。");
        }
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        if (width<=0){
            System.out.println("矩形的长和宽必须是正数。");
        }
        this.width = width;
    }
    public double area(){
        return length*width;
    }
    public double perimeter(){
        return (length+width)*2;
    }
    public String getInfo(){
        return "矩形的长为"+length+"、宽为"+width+"、面积为"+area()+"，周长为"+perimeter();
    }
}
